/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sunsite.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import sunsite.po.News;
import sunsite.po.NewsType;
import sunsite.service.NewsService;
import sunsite.service.NewsTypeService;
import sunsite.tools.ContextHelper;

/**
 *
 * @author mg
 */
public class GetNews extends ActionSupport{
    public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Messager.class);
    private List<sunsite.po.News> news;
    private List<sunsite.po.NewsType> newsTypes;
    private int pageCount;
    private int pageNow = 1;
    private int newsType = -1;

    private NewsService newsService;
    private NewsTypeService newsTypeService;

    public void setNewsTypeService(NewsTypeService newsTypeService) {
        this.newsTypeService = newsTypeService;
    }

    @Override
    public String execute() throws Exception {
        pageCount = newsService.getPageCount(newsType);
        ContextHelper.getRequest().put("pageCount", pageCount);
        ContextHelper.getRequest().put("currentType", newsType);
        news = newsService.getNews(pageNow,newsType);
        newsTypes = newsTypeService.getNewsType();
        return SUCCESS;
    }

    public List<NewsType> getNewsTypes() {
        return newsTypes;
    }

    public void setNewsTypes(List<NewsType> newsTypes) {
        this.newsTypes = newsTypes;
    }
    
    public int getNewsType() {
        return newsType;
    }

    public void setNewsType(int newsType) {
        this.newsType = newsType;
    }
    
    public List<News> getNews() {
        return news;
    }

    public void setMessages(List<News> news) {
        this.news = news;
    }

    public NewsService getNewsService() {
        return newsService;
    }

    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageNow() {
        return pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }


}
